<script>
 	import {
 		getToken
 	} from 'common/path.js'
 	import Vue from 'vue'
 	export default {
		globalData:{
			orderData:{},
			goods:{}
		},
 		onLaunch: function() {
			uni.setStorageSync('token','9dc85cc5-9553-4179-b2ae-b2b715bbdc87')
 			uni.getSystemInfo({
 				success: function(e) {
 					// #ifndef MP
 					Vue.prototype.StatusBar = e.statusBarHeight;
 					if (e.platform == 'android') {
 						Vue.prototype.CustomBar = e.statusBarHeight + 50;
 					} else {
 						Vue.prototype.CustomBar = e.statusBarHeight + 45;
 					};
 					// #endif

 					// #ifdef MP-WEIXIN
 					Vue.prototype.StatusBar = e.statusBarHeight;
 					let custom = wx.getMenuButtonBoundingClientRect();
 					Vue.prototype.Custom = custom;
 					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
 					// #endif		

 					// #ifdef MP-ALIPAY
 					Vue.prototype.StatusBar = e.statusBarHeight;
 					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
 					// #endif
 				}
 			})
 		},
 		onShow: function() {
 			this.initLogin()
 		},
 		methods: {
 			//获取token
 			getToken(openId) {
 				let data = {
 					openid: openId
 				}
 				this.$axios.axios('POST', getToken, data)
 					.then((res) => {
 						// console.log('[token]:', res.data.userinfo.token);
						uni.setStorageSync('token',res.data.userinfo.token)
						uni.setStorageSync('userInfo',res.data.userinfo)
 					})
 			},

 			//获取openid
 			initLogin() {
 				wx.cloud.init({
 					traceUser: true,
 					// env:'juchuang'
 				})
 				wx.cloud.callFunction({
 					name: 'login', // 需调用的云函数名
 					data: {}, // 传给云函数的参数
 					success: (res) => { // 成功回调
 						let openId = res.result.openid
 						// console.log('[openId]:', openId)
 						if (openId) {
 							uni.setStorageSync('openId', openId)
 							this.getToken(openId)
 						}
 					},
 					fail: (err) => {
 						console.log(err)
 					}
 				})
 			},
 		},
 		onHide: function() {}
 	}
 </script>

 <style>
 	/*每个页面公共css */
 	@import url("/colorui/main.css");
 	@import url("/colorui/animation.css");

 	input,
 	textarea {
 		font-size: 28rpx;
 	}

 	page {
 		padding-bottom: 120rpx;
 	}
 </style>
